package com.gwu.manger.dto;

import java.io.Serializable;

import io.swagger.annotations.ApiModelProperty;

/**
 * ClassName  ReponseResult
 * description 返回结果类
 *
 * @author gwu
 * @version 1.0.0
 * @date 2020/11/19
 */
public class ResponseResult implements Serializable {
    /*
       返回0表示成功，需要处理data信息
       返回非0 ，直接显示msg内容给用户
     */
	@ApiModelProperty("返回0表示成功，需要处理data信息，       返回非0 ，直接显示msg内容给用户")
    private Integer code;
    /**
     * 当返回非0的时候，错误信息内容
     */
	@ApiModelProperty("当返回非0的时候，错误信息内容")
    private String msg;
    /**
     * 处理成功，正常返回数据
     */
	@ApiModelProperty("处理成功，正常返回数据")
    private Object data;

    public ResponseResult() {
    }

    public ResponseResult(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public static ResponseResult success() {
        ResponseResult result = new ResponseResult();
        result.setResultCode(ResultCode.SUCCESS);
        return result;
    }

    public static ResponseResult success(Object data) {
        ResponseResult result = new ResponseResult();
        result.setResultCode(ResultCode.SUCCESS);
        result.setData(data);
        return result;
    }

    public static ResponseResult failure(ResultCode resultCode) {
        ResponseResult result = new ResponseResult();
        result.setResultCode(resultCode);
        return result;
    }

    public static ResponseResult failure(Integer resultCode, String errorMessage) {
        ResponseResult result = new ResponseResult();
        result.setCode(resultCode);
        result.setMsg(errorMessage);
        return result;
    }

    public static ResponseResult failure(ResultCode resultCode, Object data) {
        ResponseResult result = new ResponseResult();
        result.setResultCode(resultCode);
        result.setData(data);
        return result;
    }

    public void setResultCode(ResultCode code) {
        this.code = code.code();
        this.msg = code.message();
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }
}
